<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #fa {
            width: 600px;
            height: 600px;
            margin: 200px auto;
        }

        #fa>div {
            width: 33%;
            height: 33%;
            border: 1px solid black;
            float: left;
            line-height: 200px;
            text-align: center;
            font-size: 25px;
            font-weight: bold;
        }
    </style>
</head>

<body>
    <div id="fa">
        <div class="option">娃哈哈一瓶</div>
        <div class="option">手机一部</div>
        <div class="option">相机一部</div>
        <div class="option">自行车一辆</div>
        <div id="start">开始抽奖</div>
        <div class="option">再来一次</div>
        <div class="option">G63一辆</div>
        <div class="option">面包一箱</div>
        <div class="option">王老吉一箱</div>
    </div>

    <script>
        //获取元素
        let but = document.getElementById('start');
        let options = document.getElementsByClassName('options');

        // 控制定时器点击加快的问题
        let timer = null;

        but.onclick = function () {
            //设置一个初始值，作为时间判断
            let num = 0;
            if (timer == null) {
                timer = setInterval(() => {
                    num++;
                    //随机获取一个0-7的数
                    let ran = Math.round(Math.random() * 7);

                    //将所有元素恢复到原来的样式
                    for (let i = 0; i < options.length; i++) {
                        //给选中的元素添加样式
                        options[i].style.backgroundColor = '#fff'
                    }
                    // 
                    options[ran].style.backgroundColor = 'orange'
                    //给定时器设置有效时间，停止定时器
                    if (num == 50) {   // 50变成随机数 
                        clearInterval(timer)
                        timer = null
                    }
                }, 500)
            }
        }
    </script>
</body>

</html>